home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1990-06-22 | 8.2 KB | 179 lines | [ TEXT/MACA]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; File: DNET-TEST.LISP ; Author: Dan Suthers ; Created: 08-Jun-88 19:35:47 ; Modified: 24-Nov-89 01:34:03 (Dan Suthers) ; Language: LISP ; Package: USER ; ; Description: For testing DNET.LISP when it is changed. One should load ; this file after loading DNET and check the printed results. ; Do it for both uncompiled and compiled versions of this ; file, in SEPARATE lisp sessions. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :USER) (require :DNET) (use-package :DNET) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (format T "~%~%-------------------- DNET TESTS --------------------") (format T "~%~%---------- Variable Defining (x, y, z) ----------") (defvariable x) (defvariable y) (defvariable z) (format T "~%~%---------- DNET Manipulation ----------") (format t "~%Making a DNET called TEST with a NEW-EXPR-HOOK that prints stuff:") (format t " ~S" (make-dnet 'test :indexpr-hook '(lambda (expr terminal) (format T "~&<indexpr-hook> ~S indexed in ~S" expr terminal)) :delexpr-hook '(lambda (expr terminal) (format T "~&<delexpr-hook> ~S deleted from ~S" expr terminal)))) (format T "~%Setting the INFO of TEST to say what it is for ...") (setf (dnet-info 'test) "A discrimination net for testing the DNET code.") (format T "~%Now its INFO is:~%~S" (dnet-info 'test)) (format T "~%~%---------- Indexing Expressions ----------") (format T "~%Initializing TEST with four expressions:") (indexpr 'x 'test) (indexpr '(a b c) 'test) (indexpr '(a b junk this one) 'test) (indexpr '(x y z) 'test) (format T "~%All Expressions are (X (A B JUNK THIS ONE) (A B C) (X Y Z)): ~%~S" (all-expressions 'test)) (let ((*print-pretty* t)) (format T "~%The net itself should look like:~%") (print '(TEST (:BEGIN-LIST (X (Y (Z (:END-LIST . <VECTOR>)))) (A (B (JUNK (THIS (ONE (:END-LIST . <VECTOR>)))) (C (:END-LIST . <VECTOR>))))) (X . <VECTOR>))) (print (dnet::dnet-link (sm:gets 'dnet:dnet 'test))) (values)) (format T "~%~%---------- Deleting Expressions ----------") (format T "~%Deleting (a b junk this one):") (format T " ~S" (delexpr '(a b junk this one) 'test)) (let ((*print-pretty* t)) (format T "~%After deletion of the junk expression, the net should look like:~%") (print '(TEST (:BEGIN-LIST (X (Y (Z (:END-LIST . <VECTOR>)))) (A (B (C (:END-LIST . <VECTOR>))))) (X . <VECTOR>))) (print (dnet::dnet-link (sm:gets 'dnet:dnet 'test))) (values)) (format T "~%~%---------- More Indexing and INFO ----------") (format t "~%Adding four more test expressions: ") (indexpr '(a (b) c) 'test) (indexpr '((1) ((2)) (((3)))) 'test) (indexpr 'nil 'test) (indexpr '(nil) 'test) (format T "~%Now All expressions are:~%(X NIL (A B C) (A (B) C) (X Y Z) ((1) ((2)) (((3)))) (NIL))~%~S" (all-expressions 'test)) (format T "~%Adding info to expression ((1) ((2)) (((3)))) ... ") (setf (expr-info '((1) ((2)) (((3)))) 'test) "A list of numbers where each number is enclosed with as many parentheses.") (format T "~%Accessing that info yields:~%~S" (expr-info '((1) ((2)) (((3)))) 'test)) (format T "~%~%---------- GETEXPRing ----------") (format T "~%GETEXPR '(a (b) c): ~S" (getexpr '(a (b) c) 'test)) (format T "~%GETEXPR 'nil: ~S" (getexpr 'nil 'test)) (format T "~%GETEXPR '(nil): ~S" (getexpr '(nil) 'test)) (format T "~%~%---------- Pattern to Expression Matching ----------") (format T "~%MATCH-PATTERN '(?:x) => ~%((nil)) with bindings (((?:X))):") (multiple-value-bind (r b) (match-pattern '(?:x) 'test) (print r) (print b)) (format T "~%MATCH-PATTERN '(a ?:x c) ==> ~%((A (B) C) (A B C)) with bindings (((?:X B)) ((?:X . B))):") (multiple-value-bind (r b) (match-pattern '(a ?:x c) 'test) (print r) (print b)) (format T "~%MATCH-PATTERN '((?:x) ((?:y)) (((?:z)))) ==> ~%(((1) ((2)) (((3))))) with bindings (((?:Z . 3) (?:Y . 2) (?:X . 1))):") (multiple-value-bind (r b) (match-pattern '((?:x) ((?:y)) (((?:z)))) 'test) (print r) (print b)) (format T "~%MATCH-PATTERN '(a ?:x ?:x) ==> no match:") (multiple-value-bind (r b) (match-pattern '(a ?:x ?:x) 'test) (print r) (print b)) (format T "~%MATCH-PATTERN '(?:x ?:x) ==> no match (this found a bug once):") (multiple-value-bind (r b) (match-pattern '(?:x ?:x) 'test) (print r) (print b)) (format T "~%~%---------- Expression to Pattern Matching ----------") (format T "~%INDEXPR (a ?:x ?:y):") (indexpr '(a ?:x ?:y) 'test) (format T "~%MATCH-EXPRESSION 'x ==> ~%(X) with bindings (NIL):") (multiple-value-bind (r b) (match-expression 'x 'test) (print r) (print b)) (format T "~%MATCH-EXPRESSION 'nil ==> ~%(NIL) with bindings (NIL):") (multiple-value-bind (r b) (match-expression 'nil 'test) (print r) (print b)) (format T "~%MATCH-EXPRESSION '(nil) ==> ~%((NIL)) with bindings (NIL):") (multiple-value-bind (r b) (match-expression '(nil) 'test) (print r) (print b)) (format T "~%MATCH-EXPRESSION '(a b c) ==> ~%((A B C) (A ?:X ?:Y)) with bindings (NIL ((?:Y . C) (?:X . B))):") (multiple-value-bind (r b) (match-expression '(a b c) 'test) (print r) (print b)) (format T "~%MATCH-EXPRESSION '?:x ==> NIL and NIL:") (multiple-value-bind (r b) (match-expression '?:x 'test) (print r) (print b)) (format T "~%But now we add ?:x to the dnet (which matches anything) ...") (indexpr '?:x 'test) (format T "~%MATCH-EXPRESSION '?:x ==> ~%(?:X) with bindings (((?:X . ?:X))):") (multiple-value-bind (r b) (match-expression '?:x 'test) (print r) (print b)) (format T "~%That was to test for removing duplicates.") (format T "~%MATCH-EXPRESSION '(a small dog) ==> ~%((A ?:X ?:Y) ?:X) with bindings (((?:Y . DOG) (?:X . SMALL)) ((?:X A SMALL DOG))):") (multiple-value-bind (r b) (match-expression '(a small dog) 'test) (print r) (print b)) (format T "~%~%---------- Pattern to Pattern Matching ----------") (format T "~%To prepare, INDEXPR (a ?:y ?:y) and (a b b) and DELEXPR ?:x and (a (b) c) ...") (indexpr '(a ?:y ?:y) 'test) (indexpr '(a b b) 'test) (delexpr '?:x 'test) (delexpr '(a (b) c) 'test) (format T "~%MATCH '(a b c) ==> ~%((A B C) (A ?:X ?:Y)) with bindings (NIL NIL) and (NIL ((?:Y . C) (?:X . B))):") (multiple-value-bind (r b1 b2) (match '(a b c) 'test) (print r) (print b1) (print b2) (values)) (format T "~%MATCH '(a c c) ==> ~%((A ?:X ?:Y) (A ?:Y ?:Y)); (NIL NIL); (((?:Y . C) (?:X . C)) ((?:Y . C))):") (multiple-value-bind (r b1 b2) (match '(a c c) 'test) (print r) (print b1) (print b2) (values)) (format T "~%MATCH '(a ?:x c) ==> ~%((A B C) (A ?:Y ?:Y) (A ?:X ?:Y)); (((?:X . B)) ((?:X . ?:Y)) NIL); (NIL ((?:Y . C)) ((?:Y . C))):") (multiple-value-bind (r b1 b2) (match '(a ?:x c) 'test) (print r) (print b1) (print b2) (values)) (format T "~%MATCH '(a b ?:y) ==> ~%((A B B) (A B C) (A ?:X ?:Y) (A ?:Y ?:Y)); (((?:Y . B)) ((?:Y . C)) NIL NIL); (NIL NIL ((?:X . B)) ((?:Y . B))):") (multiple-value-bind (r b1 b2) (match '(a b ?:y) 'test) (print r) (print b1) (print b2) (values)) (format T "~%MATCH '(a ?:x ?:y) ==> ~%((A ?:Y ?:Y) (A ?:X ?:Y) (A B B) (A B C)); (((?:X . ?:Y)) NIL ((?:Y . B) (?:X . B)) ((?:Y . C) (?:X . B))); (NIL NIL NIL NIL):") (multiple-value-bind (r b1 b2) (match '(a ?:x ?:y) 'test) (print r) (print b1) (print b2) (values)) (format T "~%~%---------- Substitute Vars ----------") (format T "~%((?:x . mortal) (?:y . socrates)) into (implies (man ?:y) (?:x ?:y)) ==>~ ~%(IMPLIES (MAN SOCRATES) (MORTAL SOCRATES))") (format T "~%~A" (substitute-bindings '((?:x . mortal) (?:y . socrates)) '(implies (man ?:y) (?:x ?:y)))) (format T "~%Substitute NIL into '(a b (c) d): ~S" (substitute-bindings nil '(a b (c) d))) (format T "~%Substitute '((?:x . foo)) into NIL: ~S" (substitute-bindings '((?:x . foo)) nil)) (format T "~%~%---------- END OF DNET TEST ---------- Note: to be sure, try loading both lisp and compiled versions of this test, IN DIFFERENT LISP SESSIONS, so the second test does not rely on things defined in the first.~%") ;;; EOF